//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;

namespace OpenLS.Spreadsheet
{
    class HashListNoDuplicate<T>: IEnumerable<T>
    {
        public HashListNoDuplicate()
        {

        }
        public HashListNoDuplicate(IEnumerable<T> e)
        {
            foreach (T t in e)
                Add (t);
        }
        public void Add(T t)
        {
            if (!table.ContainsKey(t))
            {
                table.Add(t, t);
            }
            //list.Add(t);
        }
        public int Count
        {
            get
            {
                return table.Count;
            }
        }

        readonly Dictionary<T, T> table = new Dictionary<T, T>();
        //readonly List<T> list = new List<T>();
        public T GetItem(T t)
        {
            T result;
            if (table.TryGetValue(t, out result))
                return result;
            Add(t);
            return t;
        }
        public IEnumerator<T> GetEnumerator()
        {
            return table.Keys.GetEnumerator();
        }

        internal bool Contains(T t)
        {
            return table.ContainsKey(t);
        }


        internal void Remove(T node)
        {
            table.Remove(node);
            //list.Remove(node);
        }


        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return table.GetEnumerator();
        }

        #endregion
    }
}
